# -*- coding: utf-8 -*-
from selenium.webdriver.chrome.webdriver import WebDriver

from zhi_dao.http_log.zhidao_http_log import ZhiDaoWebDataObtain


def get_exam_answer(chrome_driver: WebDriver):
    result = []
    exam_url = "https://studyservice-api.zhihuishu.com/gateway/t/v1/popupAnswer/lessonPopupExam"
    exam_data = ZhiDaoWebDataObtain(chrome_driver).get_data(exam_url)
    if exam_data is None:
        return result
    dto_list = exam_data.get('lessonTestQuestionUseInterfaceDtos')
    if dto_list is None:
        return result
    if len(dto_list) == 0:
        return result
    question = dto_list[0]
    test_question = question.get('testQuestion')
    options = test_question.get('questionOptions')
    for option in options:
        if option.get('result') == '1':
            result.append(option.get('sort'))
    print("答案：", result)
    return result
